﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MDIDemo.Windows
{
    public partial class frmViewGiaoDich : DevExpress.XtraEditors.XtraForm
    {
        string sErr = "";
        DataRow returnRow = null;
        public string LoaiCT = "";


        public DataRow ReturnRow
        {
            get { return returnRow; }
            set { returnRow = value; }
        }


        public frmViewGiaoDich()
        {
            InitializeComponent();
        }
        public frmViewGiaoDich(string loaict)
        {
            InitializeComponent();
            LoaiCT = loaict;
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            if (gridGiaoDich.CurrentRow != null)
            {
                if (gridGiaoDich.CurrentRow.DataRow is DataRowView)
                {
                    returnRow = ((DataRowView)gridGiaoDich.CurrentRow.DataRow).Row;
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                    Close();
                }
            }
        }

        private void frmViewGiaoDich_Load(object sender, EventArgs e)
        {
            dtpNgayGD.EditValue = frmMain.__ngayMoSo;
            LoadGiaoDich();
        }

        protected void LoadGiaoDich()
        {
            BUS.GIAODICHControl ctr = new BUS.GIAODICHControl();
            DataTable dt = ctr.GetALLByCT(null, LoaiCT, (DateTime)dtpNgayGD.EditValue, ref sErr);
            gridGiaoDich.DataSource = dt;
        }

        private void btnLamTuoi_Click(object sender, EventArgs e)
        {
            LoadGiaoDich();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }



        private void dtpNgayGD_EditValueChanged(object sender, EventArgs e)
        {
            if (dtpNgayGD.EditValue != null)
            {
                LoadGiaoDich();
            }
        }

        private void gridGiaoDich_RowDoubleClick(object sender, Janus.Windows.GridEX.RowActionEventArgs e)
        {
            if (e.Row.DataRow is DataRowView)
            {
                returnRow = ((DataRowView)e.Row.DataRow).Row;
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
    }
}